package ru.bank.paymentprocessing.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.bank.paymentprocessing.model.PaymentType;
import ru.bank.paymentprocessing.service.PaymentService;

import java.math.BigDecimal;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class PaymentController {
    private final PaymentService paymentService;

    /**
     * Метод для обработки платежа.
     *
     * @param paymentTypeString строковое представление типа платежа
     * @param amount            сумма платежа
     * @return ResponseEntity с результатом обработки платежа
     */
    @GetMapping("/payment/{paymentTypeString}/{amount}")
    public ResponseEntity<String> processPayment(@PathVariable String paymentTypeString, @PathVariable BigDecimal amount) {
        var paymentType = PaymentType.fromString(paymentTypeString);
        var paymentResult = paymentService.processPayment(paymentType, amount);
        return ResponseEntity.ok(paymentResult);
    }
}
